#include "StdAfx.h"
#include "Tree.h"


Tree::Tree(void)
{
}


Tree::~Tree(void)
{
}

void Tree::Add(Tree** node, int NewVal)
{
	if(*node == NULL)
	{
		*node = new Tree;
		(*node)->val = NewVal;
		(*node)->l=(*node)->r=NULL;
	}
	else
	{
		if((*node)->val > NewVal) 
			Add(&(*node)->r,NewVal);
		else 
			Add(&(*node)->l,NewVal);
	}
}

void Tree::Show(Tree *&node) 
{
    if (node!=NULL) 
    {
       Show(node->l); 
	   if(node->l != NULL)
		   cout << node->val << "\n"; 
	   else cout << "        " << node->val << "\n"; 
       Show(node->r);
    }
	
}

bool Tree::Srch(Tree* node, int el)
{
	if (!node) return false; if (node->val == el) return true;
    if (Srch(node->l,el)) return true;
    return Srch(node->r,el);
}